import 'package:flutter/material.dart';

class If extends StatelessWidget {
  const If({
    @required this.dif,
    @required this.ifView,
    this.elseView,
    Key key,
  }) : super(key: key);

  final bool dif; // 相当于 v-if
  final Widget ifView; // dif为true显示的组件
  final Widget elseView; // dif为false显示的组件

  @override
  Widget build(BuildContext context) {
    if (dif && ifView != null) {
      return ifView;
    } else if (!dif && elseView != null) {
      return elseView;
    } else {
      return Container();
    }
  }
}